package cn.afactory.tygz.ui.base.title;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import cn.afactory.tygz.R;


public class TitlteBarContentView extends NoTitlteBarContentView {
	//
	private ViewGroup mTitleBarPanel;
	private Button mLeftButton;
	private ImageView mLeftIcon;
	private TextView mTitleContent;
	private Button mRightButton;
	private ImageView mRightIcon;
	private TextView mCloseBtn;

	public TitlteBarContentView(Context context) {
		super(context);
	}

	public TitlteBarContentView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public TitlteBarContentView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public int onContentLayout() {
		return R.layout.sm_base_container_layout;
	}

	@Override
	public void onContentViewCreate(View view) {
		super.onContentViewCreate(view);
		
		mTitleBarPanel = (ViewGroup) view
				.findViewById(R.id.sm_action_bar_panel);
		mLeftButton = (Button) view.findViewById(R.id.sm_titile_bar_left_btn);
		mLeftIcon = (ImageView) view.findViewById(R.id.sm_titile_bar_left_icon);
		mTitleContent = (TextView) view.findViewById(R.id.sm_title_bar_content);
		mCloseBtn = (TextView) view.findViewById(R.id.sm_titile_bar_left_btn_close);

		mRightButton = (Button) view.findViewById(R.id.sm_title_bar_btn_right);
		mRightIcon = (ImageView) view.findViewById(R.id.sm_title_bar_iv_right);

	}

	@Override
	public void setTitleText(String title) {
		mTitleContent.setText(title);
	}

	@Override
	public void setTitleText(int title) {
		setTitleText(mContext.getString(title));
	}

	@Override
	public void setLeftButton(String btnText, View.OnClickListener lsn) {
		mLeftIcon.setVisibility(GONE);
		mLeftButton.setVisibility(VISIBLE);
		mLeftButton.setText(btnText);
		mLeftButton.setOnClickListener(lsn);
	}

	@Override
	public void setLeftButton(int btnText, View.OnClickListener lsn) {
		setLeftButton(mContext.getString(btnText), lsn);
	}

	@Override
	public void setLeftImageView(int imageRes, View.OnClickListener lsn) {
		mLeftButton.setVisibility(GONE);
		mLeftIcon.setVisibility(VISIBLE);
		mLeftIcon.setImageResource(imageRes);
		mLeftIcon.setOnClickListener(lsn);
	}

	@Override
	public void setRightButton(String btnText, View.OnClickListener lsn) {
		mRightButton.setVisibility(VISIBLE);
		mRightIcon.setVisibility(GONE);
		mRightButton.setText(btnText);
		mRightButton.setOnClickListener(lsn);
	}

	@Override
	public void hideRightButton() {
		mRightButton.setVisibility(GONE);
	}

	@Override
	public void setRightButton(int btnText, View.OnClickListener lsn) {
		setRightButton(mContext.getString(btnText), lsn);
	}

	@Override
	public void setRightImageView(int imageRes, View.OnClickListener lsn) {
		mRightButton.setVisibility(GONE);
		mRightIcon.setVisibility(VISIBLE);
		mRightIcon.setImageResource(imageRes);
		mRightIcon.setOnClickListener(lsn);
	}

	@Override
	public void showTitleBar(boolean show) {
		if (mTitleBarPanel != null) {
			mTitleBarPanel.setVisibility(show ? VISIBLE : GONE);
		}
	}

	@Override
	public void setDefaultBackActoin(View.OnClickListener lsn) {
		mLeftIcon.setVisibility(VISIBLE);
		mLeftIcon.setOnClickListener(lsn);
	}
	
	@Override
	public void showCloseButton(boolean show, View.OnClickListener lsn) {
		if (show) {
			mCloseBtn.setVisibility(VISIBLE);
			mCloseBtn.setOnClickListener(lsn);
		} else {
			mCloseBtn.setVisibility(GONE);
		}
	}

}
